home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Camelot / Camelot 078 (1990-06)(Swedish User Group of Amiga)(SE)(PD)[WB].zip / Camelot 078 (1990-06)(Swedish User Group of Amiga)(SE)(PD)[WB].adf / MSH / src / han.h < prev    next >
C/C++ Source or Header  |  1990-06-17  |  9KB  |  315 lines

  1. /*-
  2.  *  $Id: han.h,v 1.30 90/06/04 23:18:28 Rhialto Rel $
  3.  *  $Log:    han.h,v $
  4.  * Revision 1.30  90/06/04  23:18:28  Rhialto
  5.  * Release 1 Patch 3
  6.  * 
  7.  *  The header file for the MESSYDOS: file system handler
  8.  *
  9.  *  This code is (C) Copyright 1989 by Olaf Seibert. All rights reserved. May
  10.  *  not be used or copied without a licence.
  11. -*/
  12.  
  13. #include "dev.h"
  14.  
  15. #define MODE_READWRITE    1004L
  16. #define MODE_CREATEFILE (1L<<31)
  17. #define FILE_DIR     2
  18. #define FILE_FILE   -3
  19.  
  20. /* #define MS_BPS      512    /* Bytes per sector */
  21. #define MS_SPC        2        /* Sectors per cluster */
  22. #define MS_RES        1        /* Reserved sectors (boot block) */
  23. #define MS_NFATS    2        /* Number of FATs */
  24. #define MS_NDIRS    112     /* Number of directory entries */
  25. #define MS_NSECTS   1440    /* total number of sectors */
  26. #define MS_SPF        3        /* Sectors per FAT */
  27. /* #define MS_SPT      9    /* Sectors per track */
  28. /* #define MS_SPT_MAX  9    /* Max sectors per track */
  29. /* #define MS_NSIDES   2    /* Tracks per cylinder */
  30. #define MS_ROOTDIR  (MS_RES + MS_SPF * MS_NFATS)
  31. #define MS_DIRENTSIZE  sizeof(struct MsDirEntry) /* size of a directory entry */
  32.  
  33. #define MS_FIRSTCLUST    2    /* Very strange convention... */
  34.  
  35. #define FAT_EOF     0xFFFF    /* end of file FAT entry */
  36. #define FAT_UNUSED  0        /* unused block */
  37. #define SEC_EOF     -1        /* end of FAT chain */
  38. #define ROOT_SEC    -1        /* where the root directory 'is' */
  39.  
  40. #define DIR_DELETED        0xE5
  41. #define DIR_DELETED_MASK    0x80
  42.  
  43. /*
  44.  * This structure has its byte order wrong, when it is on the disk.
  45.  */
  46.  
  47. struct MsDirEntry {
  48.     byte        msd_Name[8];
  49.     byte        msd_Ext[3];
  50.     byte        msd_Attributes;
  51.     byte        msd_Pad1[10];
  52.     word        msd_Time;
  53.     word        msd_Date;
  54.     word        msd_Cluster;
  55.     ulong        msd_Filesize;
  56. };
  57.  
  58. #define ATTR_READONLY        0x01
  59. #define ATTR_HIDDEN        0x02
  60. #define ATTR_SYSTEM        0x04
  61. #define ATTR_VOLUMELABEL    0x08
  62. #define ATTR_DIRECTORY        0x10
  63. #define ATTR_ARCHIVED        0x20
  64.  
  65. #define ATTR_DIR        (ATTR_DIRECTORY | ATTR_VOLUMELABEL)
  66.  
  67. #define DATE_MIN        0x21
  68.  
  69. struct DirEntry {
  70.     struct MsDirEntry de_Msd;
  71.     word        de_Sector;
  72.     word        de_Offset;
  73. };
  74.  
  75. struct DiskParam {
  76.     word        bps;    /* bytes per sector. max MS_BPS supported */
  77.     byte        spc;    /* sectors per cluster */
  78.     word        res;    /* reserved sectors (boot block) */
  79.     byte        nfats;    /* number of fats */
  80.     word        ndirs;    /* number of directory entries */
  81.     word        nsects;    /* total number of sectors on disk */
  82.     byte        media;    /* media byte */
  83.     word        spf;    /* sectors per fat */
  84.     word        spt;    /* sectors per track. Only MS_SPT
  85.                  * supported */
  86.     word        nsides;    /* # sides. Max MS_NSIDES supported */
  87.     word        nhid;    /* Number of hidden sectors */
  88.     /* derived parameters */
  89.     word        start;    /* sector of cluster 0 */
  90.     word        maxclst;    /* highest cluster number */
  91.     word        rootdir;    /* first sector of root dir */
  92.     word        ndirsects;    /* # of root directory sectors */
  93.     word        datablock;    /* first block available for files &c */
  94.     word        bpc;    /* bytes per cluster */
  95.     word        nsectsfree; /* amount of free space */
  96.     long        lowcyl;    /* offset to lowcyl */
  97.     struct DirEntry vollabel;    /* copy of volume label */
  98.     word        fat16bits;    /* Is the FAT 16 bits/entry? */
  99. };
  100.  
  101. /*
  102.  * A pointer to an MSFileLock is put into the fl_Key field of a DOS
  103.  * FileLock structure. We share the MSFileLock with all FileLocks on the
  104.  * same file. This way, you can compare FileLocks based on their fl_Key
  105.  * and fl_Task fields, as seems to be done sometimes. Also, a pointer to
  106.  * an MSFileLock is put in MSFileHandles.
  107.  *
  108.  * For ease, we keep a copy of the directory entry in core, WITH THE BYTE
  109.  * ORDER CORRECTED FOR THIS PROCESSOR.
  110.  */
  111.  
  112. struct MSFileLock {
  113.     struct MinNode  msfl_Node;
  114.     short        msfl_Refcount;    /* -1: exclusive, >0: # of shared
  115.                      * locks */
  116.     struct MSFileLock *msfl_Parent;    /* Pointer to parent directory */
  117.     struct MsDirEntry msfl_Msd; /* Copy of directory entry */
  118.     word        msfl_DirSector;    /* Location of directory entry */
  119.     word        msfl_DirOffset;
  120. };
  121.  
  122. /*
  123.  * A pointer to an MSFileHandle is put into the fh_Arg1 field of a DOS
  124.  * FileHandle. We get that value with many DOS packets that manipulate the
  125.  * contents of a file.
  126.  */
  127.  
  128. struct MSFileHandle {
  129.     struct MSFileLock *msfh_FileLock;
  130.     long        msfh_SeekPos;
  131.     word        msfh_Cluster;
  132. };
  133.  
  134. /*
  135.  * Return values of CompareNames.
  136.  */
  137.  
  138. #define CMP_NOT_EQUAL        0    /* Names do not match at all */
  139. #define CMP_OK_DIR        1    /* Name matches with a subdir entry */
  140. #define CMP_OK_FILE        2    /* Name matches with a file entry */
  141. #define CMP_INVALID        3    /* First part of name matches with a file
  142.                  * entry, or other invalid component name */
  143. #define CMP_FREE_SLOT        5
  144. #define CMP_END_OF_DIR        6
  145.  
  146. struct LockList {
  147.     struct MinList  ll_List;
  148.     void       *ll_Cookie;    /* we don't want to know what this is! */
  149. };
  150.  
  151. struct CacheSec {
  152.     struct MinNode  sec_Node;
  153.     word        sec_Number;
  154.     word        sec_Refcount;
  155.     byte        sec_Data[2];/* Really Disk.bps */
  156. };
  157.  
  158. #define SEC_DIRTY   0x8000    /* Bit in sec_Refcount */
  159.  
  160. #define OFFSETOF(tag, member)   ((long)(&((struct tag *)0)->member))
  161.  
  162. #define     DELAY_OFF        0    /* Motor is off */
  163. #define     DELAY_RUNNING1  1    /* Motor may be on */
  164. #define     DELAY_RUNNING2  2    /* Motor may be on */
  165. #define     DELAY_RUNNING   3    /* Running1 | 2 */
  166. #define     DELAY_DIRTY     4    /* We have dirty buffers to flush */
  167.  
  168.  
  169. extern long    Wait();
  170. extern struct MsgPort *CreatePort();
  171. extern struct IOExtTD *CreateExtIO();
  172. extern void    *AllocMem(), FreeMem();
  173. extern byte    *index(), *rindex();
  174. extern void    *CheckIO();
  175. extern long    AutoRequest();
  176.  
  177. /*
  178.  * PACK.C
  179.  */
  180. extern char    *DevName;
  181. extern long    UnitNr;
  182. extern long    DosType;
  183. extern ulong    DevFlags;
  184. extern struct DosPacket *DosPacket;
  185. extern struct DeviceList *VolNode;
  186. extern short    DiskChanged;
  187.  
  188. /*
  189.  * HANMAIN.C
  190.  */
  191. extern byte    ToUpper();
  192. extern long    lmin();
  193. extern byte    *ZapSpaces();
  194. extern byte    *ToMSName();
  195. extern long    MSDiskInfo();
  196. extern void    MSDiskInserted();
  197. extern int    MSDiskRemoved();
  198. extern void    HanCloseDown();
  199. extern int    HanOpenUp();
  200.  
  201. /*
  202.  * HANSEC.C
  203.  */
  204. extern struct MsgPort *DiskReplyPort;
  205. extern struct IOExtTD *DiskIOReq;
  206. extern struct IOStdReq *DiskChangeReq;
  207. extern struct DiskParam Disk;
  208. extern byte    *Fat;
  209. extern short    FatDirty;    /* Fat must be written to disk */
  210. extern short    error;        /* To put the error value; for Result2 */
  211. extern long    IDDiskState;    /* InfoData.id_DiskState */
  212. extern long    IDDiskType;    /* InfoData.id_DiskType */
  213. extern struct timerequest *TimeIOReq;    /* For motor-off delay */
  214. extern struct MinList CacheList;/* Sector cache */
  215. extern int    CurrentCache;    /* How many cached buffers do we have */
  216. extern int    MaxCache;    /* Maximum amount of cached buffers */
  217. extern ulong    BufMemType;
  218. extern long    CacheBlockSize; /* Size of disk block + overhead */
  219. extern int    DelayState;
  220. extern byte    *Word8086;
  221. extern word    Get8086Word();
  222. extern word    OtherEndianWord();
  223. extern ulong    OtherEndianLong();
  224. extern void    OtherEndianMsd();
  225. extern word    ClusterToSector();
  226. extern word    ClusterOffsetToSector();
  227. extern word    DirClusterToSector();
  228. extern word    SectorToCluster();
  229. extern word    NextCluster();
  230. extern word    NextClusteredSector();
  231. extern word    FindFreeSector();
  232. extern struct CacheSec *FindSecByNumber();
  233. extern struct CacheSec *FindSecByBuffer();
  234. extern struct CacheSec *NewCacheSector();
  235. extern void    FreeCacheSector();
  236. extern void    InitCacheList();
  237. extern void    FreeCacheList();
  238. extern void    MSUpdate();
  239. extern void    StartTimer();
  240. extern byte    *GetSec();
  241. extern byte    *EmptySec();
  242. extern void    PutSec();
  243. extern void    FreeSec();
  244. extern void    MarkSecDirty();
  245. extern void    WriteFat();
  246. extern int    ReadBootBlock();
  247. extern int    IdentifyDisk();
  248. extern int    TDMotorOff();
  249. extern int    TDGetNumCyls();
  250.  
  251. /*
  252.  * HANLOCK.C
  253.  */
  254. extern struct LockList *LockList;    /* List of all locked files we
  255.                      * have. Note this is not the same
  256.                      * as all locks we have */
  257. extern struct MSFileLock *RootLock;    /* Lock on root directory */
  258. extern struct MSFileLock *EmptyFileLock;    /* 2nd result of MSLock() */
  259.  
  260. extern struct DirEntry FakeRootDirEntry;
  261. extern int    CompareNames();
  262. extern void    NextDirEntry();
  263. extern struct DirEntry *FindNext();
  264. extern struct MSFileLock *MakeLock();
  265. extern void    WriteLock();
  266. extern void    PrintDirEntry();
  267. extern struct MSFileLock *MSLock();
  268. extern struct MSFileLock *MSDupLock();
  269. extern struct MSFileLock *MSParentDir();
  270. extern int    MSUnLock();
  271. extern void    ExamineDirEntry();
  272. extern int    MSExamine();
  273. extern int    MSExNext();
  274. extern long    MSSetProtect();
  275. extern void    WriteFileLock();
  276. extern void    UpdateFileLock();
  277. extern struct LockList *NewLockList();
  278. extern void    FreeLockList();
  279.  
  280. /*
  281.  * HANFILE.C
  282.  */
  283. extern int    GetFat();
  284. extern void    FreeFat();
  285. extern word    GetFatEntry();
  286. extern void    SetFatEntry();
  287. extern word    FindFreeCluster();
  288. extern word    ExtendClusterChain();
  289. extern void    FreeClusterChain();
  290. extern struct MSFileHandle *MSOpen();
  291. extern void    MSClose();
  292. extern long    MSSeek();
  293. extern long    MSRead();
  294. extern long    MSWrite();
  295. extern long    MSDeleteFile();
  296. extern long    MSSetDate();
  297. extern struct MSFileLock *MSCreateDir();
  298.  
  299. /*
  300.  * HANREQ.C
  301.  */
  302. extern short    Cancel;     /* Cancel all R/W errors */
  303. extern long    RetryRwError();
  304.  
  305. /*
  306.  * HANCMD.C
  307.  */
  308. extern void    HandleCommand();
  309.  
  310. /*
  311.  * DATE.C
  312.  */
  313. extern void    ToDateStamp();
  314. extern void    ToMSDate();
  315.